package com.yayan.beautyclub.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.yayan.beautyclub.bean.Keep;
import com.yayan.beautyclub.dao.IKeepDao;
import com.yayan.beautyclub.dao.KeepDao;

@Service
public class KeepService implements IKeepService {
	
	private IKeepDao keepDao;
	
	public KeepService(){
		keepDao = new KeepDao();
	}

	@Override
	public List<Map<String, Object>> getKeepByUserId(long uId, int page, int size) {
		// TODO Auto-generated method stub
		List<Map<String, Object>> list = null;
		try{
			if(uId != 0L && page >= 0 && size > 0){
				list = keepDao.getKeepByUserId(uId, page, size);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public Map<String, Object> getKeepByKeepId(long kId) {
		// TODO Auto-generated method stub
		Map<String, Object> map = null;
		try{
			if(kId != 0L){
				map = keepDao.getKeepByKeepId(kId);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return map;
	}

	@Override
	public long saveKeep(Keep keep) {
		// TODO Auto-generated method stub
		long r = 0L;
		try{
			if(keep.getpId() != 0L && keep.getuId() != 0L){
				if(keep.getkTime() == null){
					keep.setkTime(new Date());
				}
				r = keepDao.save(keep);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return r;
	}

	@Override
	public boolean deleteKeep(long kId) {
		// TODO Auto-generated method stub
		boolean res = false;
		try{
			if(kId != 0L){
				res = keepDao.delete(kId);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return res;
	}

}
